home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_085 / csh / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  145 lines

  1.  
  2. /*
  3.  * MAIN.C
  4.  *
  5.  * Matthew Dillon, 24 Feb 1986
  6.  * (c)1986 Matthew Dillon     9 October 1986
  7.  *
  8.  * version 2.06M (Manx Version and Additions) by Steve Drew 28-May-87
  9.  *
  10.  */
  11.  
  12. #include "shell.h"
  13.  
  14.  
  15. int aux; /* for use with aux: driver */
  16.  
  17. char Inline[256];
  18. #ifndef AZTEC_C
  19. char stdout_buff[STDBUF];
  20. #endif
  21.  
  22. main(argc, argv)
  23. register char *argv[];
  24. {
  25. #ifdef AZTEC_C
  26.    char *rawgets();
  27. #endif
  28.    char *prompt;
  29.    register int i;
  30.    extern int Enable_Abort;
  31.    init_vars();
  32.    init();
  33.    seterr();
  34.    do_pwd(NULL); /* set $_cwd */
  35.  
  36.    Enable_Abort = 0;
  37.  
  38.    for (i = 1; i < argc; ++i) {
  39.       if (argv[i][0] == '-' && argv[i][1] == 'c') {
  40.         Inline[0] = ' ';
  41.         Inline[1] = '\000';
  42.         while (++i < argc) {
  43.         strcat(Inline,argv[i]);
  44.         strcat(Inline," ");
  45.         }
  46.         exec_command(Inline);
  47.         main_exit(0);
  48.         }
  49.       if (argv[i][0] == '-' && argv[i][1] == 'a') {
  50.       aux = 1;
  51.       continue;
  52.       }
  53.       strcpy (Inline, "source ");
  54.       strcat (Inline, argv[i]);
  55.       av[1] = argv[i];
  56.       do_source (Inline);
  57.    }
  58.  
  59.    for (;;) {
  60.       if ((prompt = get_var (LEVEL_SET, V_PROMPT)) == NULL)
  61.      prompt = "$ ";
  62.       if (breakcheck()) {
  63.      while (WaitForChar(Input(), 100L) || stdin->_bp < stdin->_bend)
  64.         gets(Inline);
  65.       }
  66. #ifdef AZTEC_C
  67.       if (Quit || !rawgets(Inline, prompt))
  68. #else
  69.       printf("%s",prompt);
  70.       if (Quit || !gets(Inline))
  71. #endif
  72.      main_exit(0);
  73.       breakreset();
  74.       if (*Inline)
  75.      exec_command(Inline);
  76.    }
  77. }
  78.  
  79. init_vars()
  80. {
  81.    if (IsInteractive(Input()))
  82.       set_var (LEVEL_SET, V_PROMPT, "$ ");
  83.    else
  84.       set_var (LEVEL_SET, V_PROMPT, "");
  85.    set_var (LEVEL_SET, V_HIST,     "20");
  86.    set_var (LEVEL_SET, V_LASTERR, "0");
  87.    set_var (LEVEL_SET, V_PATH, "ram:,ram:c/,c:,df1:c/,df0:c/");
  88.    set_var (LEVEL_SET, "_insert", "1");
  89. }
  90.  
  91. init()
  92. {
  93.    static char pipe1[32], pipe2[32];
  94.  
  95.    stdin->_flags  |= 0x80;         /* make sure we're set as a tty */
  96.    stdout->_flags |= 0x80;       /* incase of redirection in .login */
  97.  
  98. #ifdef AZTEC_C
  99.    Close(_devtab[2].fd);
  100.    _devtab[2].mode |= O_STDIO;
  101.    _devtab[2].fd = _devtab[1].fd;  /* set stderr to Output() otherwise */
  102.                    /* don't work with aux driver       */
  103. #else
  104.    stdout->_buff = stdout_buff;
  105.    stdout->_buflen = STDBUF;
  106. #endif
  107.  
  108.    Myprocess = (struct Process *)FindTask(0L);
  109.    Uniq     = (long)Myprocess;
  110.    Pipe1 = pipe1;
  111.    Pipe2 = pipe2;
  112.    sprintf (pipe1, "ram:pipe1_%ld", Uniq);
  113.    sprintf (pipe2, "ram:pipe2_%ld", Uniq);
  114. }
  115.  
  116.  
  117. main_exit(n)
  118. {
  119.    exit (n);
  120. }
  121.  
  122. breakcheck()
  123. {
  124.    return (int)(SetSignal(0L,0L) & SIGBREAKF_CTRL_C);
  125. }
  126.  
  127. breakreset()
  128. {
  129.    SetSignal(0L, SIGBREAKF_CTRL_C);
  130. }
  131.  
  132.  
  133. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  134. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  135. /* is zero).  Since we want to check for our own ^C's             */
  136.  
  137. Chk_Abort()
  138. {
  139. return(0);
  140. }
  141.  
  142. _wb_parse()
  143. {
  144. }
  145.